home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 235 / Issue 235 - September 2007 - DPCS0907DVD.ISO / Extras / NetObjects Fusion / NOF10.exe / data1.cab / FSI / lib / nof / html / App.js next >
Encoding:
Text File  |  2007-04-11  |  9.5 KB  |  313 lines

  1. /****i* SOURCE_FILE/INFO
  2.     *
  3.     * NAME
  4.     *  App.js
  5.     *
  6.     * USAGE
  7.     *  Part of Netobjects JavaScript Library.
  8.     *
  9.     * COPYRIGHT
  10.     *  Copyright ⌐ 2000-2005 Website Pros, Inc.
  11.     *  All Rights Reserved.
  12.     *
  13.     *  This is an unpublished work protected by Website Pros, Inc.
  14.     *  as a trade secret, and is not to be used or disclosed except as
  15.     *  expressly provided in a written license agreement executed by
  16.     *  you and Website Pros, Inc.
  17.     *
  18.     *      <copyright@websitepros.com>
  19.     *
  20.     * NOTES
  21.     *  JavaScript code.
  22.     *
  23.     *****/
  24.  
  25. if (!IS_isModuleInitialized("IS.NOF.HTML.App"))
  26. {  
  27.     
  28.     /****h* NOF_JavaScript_Library/NOF.HTML.App
  29.     *
  30.     * NAME
  31.     *  NOF.HTML.App
  32.     *
  33.     * DESCRIPTION
  34.     *   Base class for all HTML applications.
  35.     *
  36.     ****/    
  37.     /**
  38.     * Constructor
  39.     * @param _name - initial name of the HTML application. Can be null.
  40.     * @param _resourcePath - initial path to resources
  41.     * @param _locale - intial locale
  42.     **/
  43.   function NOF_HTML_App ( _name, _resourcePath, _locale ) {
  44.     this.__proto__ = NOF_HTML_App.prototype;
  45.     
  46.     if (_resourcePath == null || _resourcePath.length <= 0)
  47.       _resourcePath = "resources/global";
  48.     
  49.     this.name               = _name || "generic_nof_app";
  50.     this.locale             = (_locale != null) ? _locale: NOF.UTIL.DefaultLocale;  
  51.     this.mainWindow         = null;
  52.     this.resourcePath       = _resourcePath;
  53.     this.resourceProperties = null;
  54.     
  55.     this.overridingResourcePath = null;
  56.     this.overridingResouceProperties = null;
  57.     
  58.     this.disabledEvents = null;
  59.     this.enabledEvents  = null;
  60.     this.areAllEnabled  = true;  
  61.     
  62.     this.stdErr         = NOF.Global_ERR_ConsoleLogger;
  63.     this.stdOut         = NOF.Global_OUT_ConsoleLogger;
  64.     
  65.     //this.fsiApp         = null;
  66.     //this.fsiApp2        = null;
  67.   }{
  68.         var method = NOF_HTML_App.prototype;
  69.         
  70.         /**
  71.         * Returns the name of the HTML application.
  72.         **/        
  73.         method.getName = function (){ return this.name; }
  74.  
  75.         /**
  76.         * Set the name for the HTML application.
  77.         * @param name
  78.         **/                
  79.         method.setName = function (/*String*/ name) { this.name = name; }
  80.         
  81.         /**
  82.         * Returns the main editor (window) of the HTML application.
  83.         **/                    
  84.         method.getMainWindow = function (){ return this.mainWindow; }
  85.         /**
  86.         * Set the main editor (window) for the HTML application.
  87.         * @param mainWindow
  88.         **/                            
  89.         method.setMainWindow = function (/*NOF.HTML.Window*/ mainWindow) { 
  90.           if (mainWindow != null ){
  91.             mainWindow.setApp( this );        
  92.             this.mainWindow = mainWindow;
  93.           }
  94.         }
  95.         
  96.         /**
  97.         * Initialize the HTML application i.e. call the init method of the main window.        
  98.         **/                                                    
  99.         method.init = function (){
  100.             this.getMainWindow().init();
  101.         }  
  102.         
  103.         /**
  104.         * Get the locale of the HTML application.
  105.         **/                                    
  106.         method.getLocale = function (){ return this.locale; }
  107.         /**
  108.         * Set the locale for the HTML application.
  109.         * @param locale
  110.         **/                                    
  111.         method.setLocale = function (/*NOF.UTIL.Locale*/ locale) { this.locale = locale; }
  112.         
  113.         /**
  114.         * Get the path to resource of the HTML application.
  115.         **/                                                    
  116.         method.getResourcePath = function (){ return this.resourcePath; }
  117.         /**
  118.         * Set the resource path for the HTML application.
  119.         * @param resourcePath
  120.         **/                                            
  121.         method.setResourcePath = function (/*String*/ resourcePath){ this.resourcePath = resourcePath; }
  122.     
  123.         method.getOverridingResourcePath = function (){ return this.overridingResourcePath; };
  124.         method.setOverridingResourcePath = function (overridingResourcePath){    
  125.             this.overridingResourcePath = overridingResourcePath;
  126.             this.overridingResourceProperties = null;
  127.             this.getOverridingResource();
  128.         }
  129.         method.clearOverridingResource = function () {
  130.             this.overridingResourceProperties = null;
  131.             this.overridingResourcePath = null;
  132.         }
  133.         method.getOverridingResource = function (/*NOF.UTIL.Locale*/ locale) {    
  134.             if (this.overridingResourceProperties == null && this.overridingResourcePath != null) {
  135.                 if (locale == null) locale = this.locale;
  136.                 this.overridingResourceProperties = this.getResourceFromFile (this.overridingResourcePath, locale);
  137.                 if (this.overridingResourceProperties == null)
  138.                     this.overridingResourcePath = null;                
  139.             }
  140.             return this.overridingResourceProperties;
  141.         }
  142.         
  143.         /**
  144.         * Get the associated resource of the HTML application. 
  145.         * @param locale 
  146.         * @return an instance of NOF.UTIL.PropertyResourceBundle
  147.         **/                                                    
  148.         method.getResource = function (/*NOF.UTIL.Locale*/ locale) {        
  149.             if (this.resourceProperties == null) {
  150.                 if (locale == null) locale = this.locale;
  151.                 this.resourceProperties = this.getResourceFromFile (this.resourcePath, locale);
  152.             }
  153.             return this.resourceProperties;
  154.         }
  155.         
  156.         /**
  157.         * Get the property value from the associated resource.
  158.         * @param key - name of the property
  159.         * @return property value as String or null if the resource does not contain the specified property
  160.         **/                                                            
  161.         method.getResourceProperty = function ( key ){     
  162.             if (this.overridingResourcePath != null) {
  163.                 try {
  164.                     var property = this.getOverridingResource().getProperty( key ); 
  165.                     if (property != null)
  166.                         return property;
  167.                 }catch (e) {}
  168.             }
  169.             return this.getResource().getProperty( key );     
  170.         }  
  171.         
  172.         /**
  173.         * Get a resource.
  174.         * @param resourcePath - path to the resource file.
  175.         * @param locale - NOF.UTIL.Locale object used to specify the details 
  176.         * for requested resource. If missing or null, 
  177.         * the value of current locale member variable is used.
  178.         * @return a NOF.UTIL.PropertyResourceBundle object with pairs (key/value)
  179.         * from the resource file as specified by the resourcePath. 
  180.         **/
  181.         method.getResourceFromFile = function (resourcePath, locale) {
  182.             if ( locale != null ) 
  183.                 return NOF.UTIL.ResourceBundle.getBundle(resourcePath, locale);
  184.             else
  185.                 return NOF.UTIL.ResourceBundle.getBundle(resourcePath, this.locale);  
  186.         }        
  187.     
  188.  
  189.         /** 
  190.         * Forces the resource to be reloaded
  191.         * @param newLocale.
  192.         */
  193.         method.reloadResource = function ( newLocale ) {
  194.             this.locale = newLocale;
  195.             this.resourceProperties = null;
  196.             return this.getResource();
  197.         }
  198.         
  199.         method.isMenuChangeEnabled = function () {
  200.             return this.areAllEnabled;
  201.         }
  202.         
  203.         method.isEventEnabled = function (_evt) {
  204.             if (this.areAllEnabled)
  205.                 return true;
  206.             
  207.             if (this.enabledEvents != null)
  208.                 return this.enabledEvents.contains(_evt);
  209.             if (this.disabledEvents != null)
  210.                 return !this.disabledEvents.contains(_evt);
  211.             return false;
  212.         }
  213.         
  214.         method.enableEvent = function (_evt) {
  215.             if (this.areAllEnabled)
  216.                 return true;
  217.             
  218.             if (this.enabledEvents == null)
  219.                 this.enabledEvents = new NOF.UTIL.ArrayList();
  220.             this.enabledEvents.add (_evt);
  221.             if (this.disabledEvents != null) {
  222.                 var index = this.disabledEvents.getIndex(_evt);
  223.                 if (index != -1)
  224.                     this.disabledEvents.remove(index);
  225.             }
  226.         }
  227.         
  228.         method.disableEvent = function (_evt) {
  229.             if (this.areAllEnabled)
  230.                 this.areAllEnabled = false;
  231.             
  232.             if (this.disabledEvents == null)
  233.                 this.disabledEvents = new NOF.UTIL.ArrayList();
  234.             this.disabledEvents.add (_evt);
  235.             if (this.enabledEvents != null) {
  236.                 var index = this.enabledEvents.getIndex(_evt);
  237.                 if (index != -1)
  238.                     this.enabledEvents.remove(index);
  239.             }
  240.         }
  241.         
  242.         method.enableAllEvents = function () {
  243.             this.disabledEvents = null;
  244.             this.enabledEvents  = null;
  245.             this.areAllEnabled  = true;      
  246.         }
  247.         
  248.         method.disableAllEvents = function () {
  249.             this.areAllEnabled  = false;
  250.             this.disabledEvents = null;
  251.             this.enabledEvents  = null;
  252.         }  
  253.         
  254.         /**
  255.          * Now it always dispatches all events to MainWindow.action which decides 
  256.         * whether it belongs to itself or to its children.
  257.         * @param evt name.
  258.         */
  259.         method.dispatchEvent = function ( _evt ) {    
  260.             if (_evt != null ) {
  261.                 var evtObj;
  262.                 if (typeof(_evt) != 'object'){//a simple string was passed convert it to an EventObject
  263.                     var source = (arguments.length > 1) ? arguments[1] : null;
  264.                     evtObj = new NOF.EventObject( _evt, source);
  265.                 }else{        
  266.                     evtObj = _evt;
  267.                 }
  268.                 if (this.isEventEnabled(evtObj))
  269.                     return this.getMainWindow().action( evtObj );      
  270.             }
  271.             return false;
  272.         }
  273.         
  274.         method._dispatchEvent     = method.dispatchEvent;
  275.         
  276.         method.toString = function () {
  277.             return this.getName() + " { MainWindow:" + this.getMainWindow() + ";ResourceFile:" + this.resourcePath + ";Locale:" + this.getLocale() + "}";  
  278.         }
  279.         
  280.         method.getFSIApp = function (){
  281.             return NOF.App.getFSIApp();
  282.         }
  283.         
  284.         method.getFSIApp2 = function (){
  285.             return NOF.App.getFSIApp2();
  286.         }
  287.         
  288.         /**
  289.         * Set window title in NOF fashion. Call it before anything else. 
  290.         * @param title
  291.         **/
  292.         method.setTitle = function (/*String*/ title) {    
  293.             this.getFSIApp2().SetDialogTitle(this.getResourceProperty(title));
  294.         }  
  295.         
  296.         
  297.         method.getStdErr = function (){ return this.stdErr; };
  298.         method.setStdErr = function ( _stdErr ){ this.stdErr = _stdErr; };  
  299.         
  300.         method.getStdOut = function (){ return this.stdOut; };
  301.         method.setStdOut = function ( _stdOut ){ this.stdOut = _stdOut; };  
  302.         
  303.         method.TRACE = function ( msg ){ /*this.stdOut.info( msg )*/   };    
  304.         method.ERROR = function ( msg ){ /*this.stdOut.severe( msg )*/ };      
  305.         
  306.   }
  307.   
  308.   //NOF.__proto__.HtmlApp  = NOF_HTML_App;    //namespace
  309.     HTML.__proto__.App  = NOF_HTML_App;
  310.   //NOF.addVariable("AppInstance", new NOF_HTML_App());  
  311.     NOF.addVariable("HTML.AppInstance", new NOF_HTML_App());  
  312. }
  313.